/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package astroLib;

import astroLib.APC_Vect3D.*;

/**
 *
 * @author mehmetrg
 */
public class APC_Moon{
 static double l_Moon;

    
    
//------------------------------------------------------------------------------
//
// MiniMoon: Computes the Moon's RA and declination using a low precision 
//           analytical series
//
// Input:
//
//   T         Time in Julian centuries since J2000
//
// Output:
//
//   RA        Right Ascension of the Moon in [rad]
//   Dec       Declination of the Moon in [rad]
//
//------------------------------------------------------------------------------
static  Equatorial MiniMoon (double T)
 {
  //
  // Constants
  //*BU*

 double eps =Math.toRadians( 23.43929111);
 double pi2=2*Math.PI;
 double	 Arcs      = 3600.0*180.0/Math.PI;
  //
  // Variables
  //*BU*
  double L_0, l,ls, F, D, dL, S, h, N;
  APC_Vect3D.Polar e_Moon;
  double  b_Moon; 
  
  // Mean elements of lunar orbit
  //APC_Math APCMath = new APC_Math ();
 
  L_0 = APC_Math.Frac (0.606433 + 1336.855225*T);       // mean longitude [rev]
  
  l  = pi2*APC_Math.Frac ( 0.374897 + 1325.552410*T );  // Moon's mean anomaly 
  ls = pi2*APC_Math.Frac ( 0.993133 +   99.997361*T );  // Sun's mean anomaly 
  D  = pi2*APC_Math.Frac ( 0.827361 + 1236.853086*T );  // Diff. long. Moon-Sun 
  F  = pi2*APC_Math.Frac ( 0.259086 + 1342.227825*T );  // Dist. from ascending node 
    
 
  // Perturbations in longitude and latitude
  dL = +22640* Math.sin(l) - 4586*Math.sin(l-2*D) + 2370*Math.sin(2*D) +  769*Math.sin(2*l) 
       -668*Math.sin(ls) - 412*Math.sin(2*F) - 212*Math.sin(2*l-2*D) - 206*Math.sin(l+ls-2*D)
       +192*Math.sin(l+2*D) - 165*Math.sin(ls-2*D) - 125*Math.sin(D) - 110*Math.sin(l+ls)
       +148*Math.sin(l-ls) - 55*Math.sin(2*F-2*D);
  S  = F + (dL+412*Math.sin(2*F)+541*Math.sin(ls)) / Arcs; 
  h  = F-2*D;
  N  = -526*Math.sin(h) + 44*Math.sin(l+h) - 31*Math.sin(-l+h) - 23*Math.sin(ls+h) 
       + 11*Math.sin(-ls+h) - 25*Math.sin(-2*l+F) + 21*Math.sin(-l+F);
  

  // Ecliptic longitude and latitude
  l_Moon = pi2 * APC_Math.Frac( L_0 + dL/1296.0e3 ); // [rad]3.4870735266982229//1.41
  b_Moon = ( 18520.0*Math.sin(S) + N ) / Arcs;   // [rad]-0.072743688054476285
    
  APC_Vect3D.Vec3D vectM;
  
  APC_Vect3D.Polar polar;
  polar=new Polar (l_Moon,b_Moon);
  vectM=new Vec3D(polar);// {phi = 3.4870735266982229, theta = -0.072743688054476285, r = 1} -0.93842432408479426 -0.33775356558268776 -0.072679549408194433
  
  e_Moon=APC_Vect3D.calcPolarAngles (APC_Vect3D.AbProduct(APC_Vect3D.R_x(-eps), vectM));//{m_Vec = {-0.93s42432408479426, -0.2809725733679169d, -0.201032d355791d505}, m phi = 0, m theta = 0, m r = 0, m bPolarValicl = false}
  Equatorial result = new Equatorial();
  // Equatorial coordinates

  result.RA = e_Moon.phi;//3.4325070455326463
  result.Dec = e_Moon.theta; //-0.20241216781998314
  return result;

}

}

